package logic

import (
	"context"
	"errors"
	"srv/models"

	"srv/house"
	"srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserInformationLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserInformationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInformationLogic {
	return &UserInformationLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserInformationLogic) UserInformation(in *house.UserInformationRequest) (*house.UserInformationResponse, error) {
	// todo: add your logic here and delete this line
	var newUser models.User
	err := newUser.FirstUser(int(in.UserId))
	if err != nil {
		logx.Error("用户未登录")
		return nil, errors.New("用户未登录")
	}
	user := models.User{
		UserName:            in.UserName,
		UserCard:            in.UserCard,
		UserCardStraight:    in.UserCardStraight,
		UserCardReverseSide: in.UserCardReverseSide,
	}
	err = user.UpUser(int(in.UserId))
	if err != nil {
		logx.Error("用户信息添加失败")
		return nil, errors.New("用户信息添加失败")
	}
	return &house.UserInformationResponse{}, nil
}
